package com.helasasa.maxfunds.lineofcredit.cashloan.cameroon.screen.permissions.subview

import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.widget.ImageView
import android.widget.TextView
import androidx.fragment.app.DialogFragment
import com.helasasa.maxfunds.lineofcredit.cashloan.R

interface IPermissionCameroonAskDialogListener {
    fun onClick(type: Int)
}

class PermissionCameroonAskDialog(var onItemClick: IPermissionCameroonAskDialogListener) :
    DialogFragment() {

    private lateinit var ok: TextView
    private lateinit var cancel: TextView
    private lateinit var close: ImageView

    private var pickType = 0

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?,
    ): View {
        dialog?.requestWindowFeature(Window.FEATURE_NO_TITLE)
        return inflater.inflate(R.layout.view_cameroon_permission_ask_dialog, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        dialog?.setCancelable(true)
        dialog?.setCanceledOnTouchOutside(true)

        ok = view.findViewById(R.id.ok)
        cancel = view.findViewById(R.id.cancel)
        close = view.findViewById(R.id.close)

        initializeView()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NO_TITLE, R.style.Dialog)
    }

    override fun onStart() {
        super.onStart()

        dialog?.window?.let {
            it.attributes.gravity = Gravity.CENTER
            it.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
        }
    }

    private fun initializeView() {
        ok.setOnClickListener {
            onItemClick.onClick(0)
            dismiss()
        }

        cancel.setOnClickListener {
            onItemClick.onClick(-1)
            dismiss()
        }

        close.setOnClickListener {
            dismiss()
        }
    }
}